﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
namespace Gronia.WPF.Controls
{
    [TemplatePart(Name = "PART_BusyIndicator", Type = typeof(BusyIndicator))]
    public partial class CustomWindow : Window
    {
        static CustomWindow()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomWindow), new FrameworkPropertyMetadata(typeof(CustomWindow)));
        }

        public BusyIndicator BusyIndicator { get; private set; }

        public override void OnApplyTemplate()
        {
            Button MinimizeButton = GetTemplateChild("PART_MinimizeButton") as Button;
            if (MinimizeButton != null)
            {
                MinimizeButton.Click += OnMinimizeClick;
            }

            Button RestoreButton = GetTemplateChild("PART_RestoreButton") as Button;
            if (RestoreButton != null)
            {
                RestoreButton.Click += OnRestoreClick;
            }

            Button CloseButton = GetTemplateChild("PART_CloseButton") as Button;
            if (CloseButton != null)
            {
                CloseButton.Click += OnCloseClick;
            }

            Thumb DragThumb = GetTemplateChild("PART_DragThumb") as Thumb;
            if (DragThumb != null)
            {
                DragThumb.PreviewMouseDown += OnDragThumbPreviewMouseDown;
            }

            Grid ResizeGrid = GetTemplateChild("PART_ResizeGrid") as Grid;
            if (ResizeGrid != null)
            {
                foreach (UIElement element in ResizeGrid.Children)
                {
                    Thumb resizeThumb = element as Thumb;
                    if (resizeThumb != null)
                    {
                        resizeThumb.PreviewMouseDown += OnResizeThumbPreviewMouseDown;
                    }
                }
            }
            BusyIndicator = GetTemplateChild("PART_BusyIndicator") as BusyIndicator;

            base.OnApplyTemplate();
        }
    }
}